*** Create Figure 6 ***

********************************************************************************

** read in .dta file **
use "${clean}/who_counts_analysis.dta", clear


** Run Honest DiD Event Study for all outoutcomes for 1945-1955 subset ** 

preserve
drop if YOB < 1945
drop if YOB > 1955

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe MOB b1950.Dyear, absorb(geo2_ma YOB reg_fe Arabic Female) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on Registration")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
graph save "${output}/graphs/MOB_HDID_PRE.gph", replace
graph export "${output}/graphs/MOB_HDID_PRE.png", replace


restore

* Honest DiD Test: Schooling, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1955

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe Schooling b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on Formal Schooling")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
graph save "${output}/graphs/Schooling_HDID_PRE.gph", replace
graph export "${output}/graphs/Schooling_HDID_PRE.png", replace


restore

* Honest DiD Test: Years, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1955

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe EDU_YRS b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on Formal Schooling, Years")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
graph save "${output}/graphs/YRS_HDID_PRE.gph", replace
graph export "${output}/graphs/YRS_HDID_PRE.png", replace


restore

* Honest DiD Test: Lit, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1955

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe French_Lit b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on French & Arabic Literacy")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
graph save "${output}/graphs/LIT_HDID_PRE.gph", replace
graph export "${output}/graphs/LIT_HDID_PRE.png", replace

restore

* Honest DiD Test: CM2, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1955

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe CM2 b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on Compulsory Schooling")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
graph save "${output}/graphs/CM2_HDID_PRE.gph", replace
graph export "${output}/graphs/CM2_HDID_PRE.png", replace


restore

* Honest DiD Test: LIT, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1955

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe LIT b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on Literacy")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
graph save "${output}/graphs/LIT_ANY_HDID_PRE.gph", replace
graph export "${output}/graphs/LIT_ANY_HDID_PRE.png", replace


restore

graph combine "${output}/graphs/MOB_HDID_PRE.gph" "${output}/graphs/Schooling_HDID_PRE.gph" 
graph save "${output}/graphs/PRE_Honest56_A.gph", replace
graph export "${output}/graphs/Figure6_A.png", replace

graph combine "${output}/graphs/YRS_HDID_PRE.gph" "${output}/graphs/LIT_HDID_PRE.gph"
graph save "${output}/graphs/PRE_Honest56_B.gph", replace
graph export "${output}/graphs/Figure6_B.png", replace
